<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: register.php
| Author: Nick Jones (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "maincore.php";
require_once THEMES."templates/header.php";
include LOCALE.LOCALESET."register.php";
include LOCALE.LOCALESET."user_fields.php";
//Henter avloserid fra URL
$avloserid=$_GET['avloserid'];
//---------------------------------------------------------------------------------------------------------------------+
//------Funksjon for bekreftelse og sletting av kontrakt mot DB   (Hoppes over hvis ikke slettknappen er trykket)------+
//---------------------------------------------------------------------------------------------------------------------+
if(isset($_GET['slett']))

if(isset($_GET['confirm'])) {
	$sid=$_GET['sid'];
	$confirm=$_GET['confirm'];
	if ($_GET['confirm'] == "ja" )
		{
			$query1="DELETE FROM kurs_sertifikat WHERE kursid=$sid";
			mysql_query($query1);
		header("Refresh: 1; url=lagrekurs.php?avloserid=".$_GET['avloserid']."&sjekk=nei");
		}
}
//---------------------------------------------------------------------------------------------------------------------+
//------------------------------------Slutt-på-funksjon-for-sletting-av-kontrakt---------------------------------------+
//---------------------------------------------------------------------------------------------------------------------+
//Henter sjekk fra URL
$sjekk=$_GET['sjekk'];

if($sjekk=="ja") {
	$ud_kaar=$_POST['ud_kaar'];
	$ud_ktype=$_POST['ud_ktype'];
	$ud_ksted=$_POST['ud_ksted'];
	
	//Oppkobling mot databasen. Opkoblingsinfo ligger i config.php
	$db = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_user'], $GLOBALS['db_password']);
	mysql_select_db($GLOBALS['db_name'], $db);  
	$query1="INSERT INTO kurs_sertifikat VALUES ('','',$ud_kaar,'$ud_ksted','$ud_ktype', $avloserid)";
	mysql_query($query1);
}//Slutt på IF-setning

// Her begynner koden for å hente ut data om kurs
$query="SELECT aar, kurssted, kurstype, kurs_sertifikat.avloserid, kurs_sertifikat.kursid FROM kurs_sertifikat, avloser 
		WHERE kurs_sertifikat.avloserid=avloser.avloserid 
		AND kurs_sertifikat.avloserid='$avloserid'
		ORDER by kurs_sertifikat.aar DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);

echo "<br></br>
	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='profil.php?avloserid=$avloserid'><b><---  Tilbake til profil</b></a></p>
	<table class='capmain' border='0' cellpadding='0' align='center'>
		<tr>
			<th>Kurs / Sertifikat</th>
		</tr>
	</table>
	<table class='imagetable' border='0' cellpadding='5' align='center'>
		<tr>
			<th><b>&Aring;r</b></th>
			<th><b>Sted</b></th>
			<th><b>Kurstype</b></th>
			<th><b></b></th>
		</tr>
";
$i=0;
while ($i < $num) {
	$aar=mysql_result($result,$i,"aar");
	$sted=mysql_result($result,$i,"kurssted");
	$kurstype=mysql_result($result,$i,"kurstype");
	$sid=mysql_result($result,$i,"kursid");
++$i;
echo "
	<form action='lagrekurs.php?confirm=ja&sid=".$sid."&avloserid=".$avloserid."&slett=ja&sjekk=nei' onSubmit='return validateUpdate()' method='post'>
		<tr>
			<td>$aar</td>
			<td>$sted</td>
			<td>$kurstype</td>
			<td align=center><input type='submit' value='Slett' /></td>
		</tr></form>
";
} //Slutt på While-løkke
echo "	</table>
		<form action='lagrekurs.php?avloserid=".$avloserid."&sjekk=ja' method='post' >		
		<table class='imagetable' border='1' cellpadding='5' align='center'>
			<tr>	
				<td><input type='text' maxlength='4' size='4' name='ud_kaar' value='&Aring;r'></td>		
				<td><input type='text' name='ud_ksted' value='Sted'></td>	
				<td><input type='text' name='ud_ktype' value='Kurstype'></td>	
				<td><input type='Submit' value='Legg Til'></td>
			</tr></form>
		</table><br></br>
";

//Her slutter koden for å hente ut data om skolegang
require_once THEMES."templates/footer.php";
?>
<!-- JavaScript and HTML codes by Quackit.com -->
<script language="javascript" type="text/javascript" >
function validateUpdate(){
		var confirmLeave = confirm('Er du sikker?');
		return confirmLeave;
}
</script>
